package com.gene.service.impl;

import com.gene.mapper.UserExpenditureMapper;
import com.gene.pojo.UserExpenditure;
import com.gene.pojo.UserExpenditureExample;
import com.gene.service.IUserExpenditureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserExpenditureServiceImpl implements IUserExpenditureService {
    @Autowired
    private UserExpenditureMapper userExpenditureMapper;

    @Override
    public List<UserExpenditure> query(UserExpenditure userExpenditure) {
        UserExpenditureExample example=new UserExpenditureExample();
        UserExpenditureExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userExpenditure.getUserId());
        criteria.andModeEqualTo((byte) 1);
        example.setOrderByClause("ctime DESC");
        List<UserExpenditure> list = userExpenditureMapper.selectByExample(example);
        return list;
    }

    @Override
    public boolean add(UserExpenditure userExpenditure) {
        userExpenditure.setCtime(new Date());
        int a=userExpenditureMapper.insert(userExpenditure);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(UserExpenditure userExpenditure) {
        int a=userExpenditureMapper.updateByPrimaryKeySelective(userExpenditure);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(UserExpenditure userExpenditure) {
        int a=userExpenditureMapper.deleteByPrimaryKey(userExpenditure.getExpenditureId());
        if(a==1){
            return true;
        }
        return false;
    }
}
